package com.shanghaionstar.user;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;
import com.onstar.cn.common.exception.OnStarException;
import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.common.util.Constants;
import com.onstar.cn.common.util.EncryptUtil;
import com.onstar.cn.common.util.PreferencesUtls;
import com.onstar.cn.framework.annotation.FindViewById;
import com.onstar.cn.framework.annotation.OnClick;
import com.onstar.cn.framework.common.CustomLayoutsGroup;
import com.onstar.cn.framework.mvp.base.core.BaseFragment;
import com.onstar.cn.more.response.HeadImgRes;
import com.onstar.cn.rxconstants.RxConstants;
import com.onstar.cn.weight.CustomImageView;
import com.onstar.cn.weight.ToastView;
import com.onstar.cn.weight.discover.ItemViewData;
import com.onstar.cn.weight.more.CustomTextImageLayout;
import com.onstar.cn.weight.ptr.PtrDefaultHandler;
import com.onstar.cn.weight.ptr.PtrFrameLayout;
import com.onstar.cn.weight.ptr.PtrHandler;
import com.shanghaionstar.OnstarApplication;
import com.shanghaionstar.R;
import com.shanghaionstar.activity.MainTabActivity;
import com.shanghaionstar.activity.MoreActivity;
import com.shanghaionstar.activity.webview.handler.CommonWebViewActivity;
import com.shanghaionstar.activity.webview.handler.IWebType;
import com.shanghaionstar.activity.webview.handler.WebDataEntity;
import com.shanghaionstar.enumtype.FunctionNameFindId;
import com.shanghaionstar.iview.ILoginListener;
import com.shanghaionstar.login.register.JoinMeUtils;
import com.shanghaionstar.report.bean.ReportReqParam;
import com.shanghaionstar.servicepackage.OnStarPackageListActivity;
import com.shanghaionstar.user.iview.IClearCacheView;
import com.shanghaionstar.user.iview.IMoreView;
import com.shanghaionstar.user.presenter.ClearCachePresenter;
import com.shanghaionstar.user.presenter.MorePresenter;
import com.shanghaionstar.user.renew.CurrentDataPackageActivity;
import com.shanghaionstar.utils.AlertDialogUtil;
import com.shanghaionstar.utils.ApplicationUtil;
import com.shanghaionstar.utils.BusinessUtil;
import com.shanghaionstar.utils.FinalConfigParams;
import com.shanghaionstar.utils.FinalConstants;
import com.shanghaionstar.utils.ImageUtils;
import com.shanghaionstar.utils.JoinMeConstants;
import com.shanghaionstar.utils.LoginUtil;
import com.shanghaionstar.weight.CommonProgressButton;
import com.shanghaionstar.weight.OnStarPtrHeader;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 6335yz on 2016/6/21.
 * 个人中心界面
 */
public class MoreFragment extends BaseFragment implements IMoreView, ILoginListener {

    @FindViewById
    private LinearLayout datas_layout;

    @FindViewById
    private CircleImageView user_icon;
    @FindViewById
    private CustomImageView user_icon_default, img_pullRefreshGuide;
    @FindViewById
    private TextView user_login;
    @FindViewById
    private TextView unread_tv;
    @FindViewById
    private CommonProgressButton btn_upgradetoowner;

    @FindViewById
    private RelativeLayout package_layout, data_4g_layout, ppc_layout;
    @FindViewById
    private CustomTextImageLayout pay_card;

    private ProgressDialog progress_dialog;

    private ImageLoader imageLoader;
    private DisplayImageOptions imageOptions;
    private MorePresenter presenter;
    private boolean isLoadHeadImage = false;
    private OnstarApplication application;

    @FindViewById
    private PtrFrameLayout ptrFrameLayout;

    private Context mActivity;

    private ClearCachePresenter clearCachePresenter;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mActivity = activity;
    }

    @Override
    public int getLayoutId() {
        return R.layout.tab_fragment_more;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (isFirstLoad()) {
            setUpRefreshLayout();
            presenter = new MorePresenter(((MainTabActivity) onActivity()).getScheduler());
            presenter.setView(this);
            imageLoader = ImageLoader.getInstance();
            imageOptions = ImageUtils.getOptions(true, true, R.drawable.onstar_more_default_user_icon);
            showDatas();

//            if(mActivity instanceof MainTabActivity){
//                ((MainTabActivity) mActivity).loadBroadcasts();
//            }

            btn_upgradetoowner.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (progress_dialog != null) {
                        progress_dialog.dismiss();
                        progress_dialog = null;
                    }

                    progress_dialog = new ProgressDialog(onActivity());
                    progress_dialog.setMessage(getString(R.string.sendingRequest_wait));
                    JoinMeUtils.checkVisitor(MoreFragment.this);
                    BusinessUtil.sendReportByClickType(getActivity(), FunctionNameFindId.My_updatetosubscriber.getStringValue());
                }
            });
        }
        //initButton();
    }

    public ClearCachePresenter getClearCachePresenter() {
        if (clearCachePresenter == null) {
            clearCachePresenter = new ClearCachePresenter(baseActivity.getScheduler(), baseActivity);
            clearCachePresenter.setClearCacheView(new IClearCacheView() {
                @Override
                public void onComplete(Throwable throwable) {
                    //throwable == null标识成功
                    BusinessUtil.sendReportByRequestParams(getContext(), FunctionNameFindId.My_DragDownRefresh.getStringValue(), ReportReqParam.getMineRefreshReqParam(throwable == null, throwable == null ? "" : throwable.getMessage()));
                    ptrFrameLayout.refreshComplete();
                }
            });
        }
        return clearCachePresenter;
    }

    private void setUpRefreshLayout() {
        OnStarPtrHeader header = new OnStarPtrHeader(baseActivity);
        ptrFrameLayout.setEnabled(false);
        ptrFrameLayout.setHeaderView(header);
        ptrFrameLayout.addPtrUIHandler(header);
        ptrFrameLayout.setBackgroundColor(ContextCompat.getColor(baseActivity, R.color.white));
        ptrFrameLayout.setPtrHandler(new PtrHandler() {
            @Override
            public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
                return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
            }

            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                hidePullRefreshGuide();
                asyncData();
            }
        });
    }

    /**
     * 同步服务器数据(4g,安吉星套餐)
     */
    private void asyncData() {
//        UserCenterCacheHelper.getInstance().updateAsync(baseActivity);
        getClearCachePresenter().clearCache();
    }

    @Override
    public void onResume() {
        super.onResume();
        initButton();
        showRedMark();
        resetOpManulLink();
    }

    /**
     * 地址只区别gen9和其他情况，只有gen9的车用户手册地址是：http://om.onstar.com.cn/manual/wap9/index.jsp
     * 其他情况地址一律是：http://om.onstar.com.cn/manual/wap10/index.jsp
     */
    private String USER_GUIDE_LINK = "";//默认是gen10
    private static final String USER_GUIDE_GEN9_SUFFIX = "/manual/wap9/index.jsp";
    private static final String USER_GUIDE_GEN10_SUFFIX = "/manual/wap10/index.jsp";
//    private static final String USER_GUIDE_GEN9_SUFFIX = "/onstar/wap9/index.jsp";
//    private static final String USER_GUIDE_GEN10_SUFFIX = "/onstar/wap10/index.jsp";

    private void initButton() {
        USER_GUIDE_LINK = Constants.CURRENT_PREFIX_USER_GUIDE_URL + USER_GUIDE_GEN10_SUFFIX;
        if (ApplicationUtil.getInstance().isLogin()) {

            ptrFrameLayout.setEnabled(true);
            showPullRefreshGuide();

            user_login.setText(R.string.category_option);

            if (ApplicationUtil.getInstance().getLoginRole().equalsIgnoreCase(JoinMeConstants.VISITOR)) {
                package_layout.setVisibility(View.VISIBLE);
                data_4g_layout.setVisibility(View.GONE);
                ppc_layout.setVisibility(View.VISIBLE);
                btn_upgradetoowner.setVisibility(View.VISIBLE);
            } else if (ApplicationUtil.getInstance().isGen10()) {
                package_layout.setVisibility(View.VISIBLE);
                data_4g_layout.setVisibility(View.VISIBLE);
                ppc_layout.setVisibility(View.VISIBLE);
                btn_upgradetoowner.setVisibility(View.GONE);
            } else {
                USER_GUIDE_LINK = Constants.CURRENT_PREFIX_USER_GUIDE_URL + USER_GUIDE_GEN9_SUFFIX;//gen9车辆
                package_layout.setVisibility(View.VISIBLE);
                data_4g_layout.setVisibility(View.GONE);
                ppc_layout.setVisibility(View.VISIBLE);
                btn_upgradetoowner.setVisibility(View.GONE);
            }

            application = OnstarApplication.getApplication();
            showHeadImage(application.getHeadImgRes());
        } else {
            ptrFrameLayout.setEnabled(false);
            user_login.setText(R.string.user_login_register);
            package_layout.setVisibility(View.VISIBLE);
            data_4g_layout.setVisibility(View.VISIBLE);
            ppc_layout.setVisibility(View.VISIBLE);
            btn_upgradetoowner.setVisibility(View.GONE);
            user_icon.setVisibility(View.GONE);
            user_icon_default.setVisibility(View.VISIBLE);
            user_icon_default.setImageResource(R.drawable.onstar_more_default_user_icon);
            isLoadHeadImage = false;
        }
    }

    private void showHeadImage(final HeadImgRes headImgRes) {
        if (headImgRes != null && !CommonUtil.isNull(headImgRes.getFullUrl())) {
            user_icon_default.setVisibility(View.GONE);
            if (!headImgRes.getFullUrl().equals(user_icon.getTag())) {
                imageLoader.displayImage(headImgRes.getFullUrl(), user_icon, imageOptions, new SimpleImageLoadingListener() {
                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                        super.onLoadingComplete(imageUri, view, loadedImage);
                        user_icon.setTag(headImgRes.getFullUrl());
                    }
                });
            }
            user_icon.setVisibility(View.VISIBLE);
        } else {
            //读取头像 头像更换成功后需要重新下拉
            if (!isLoadHeadImage || (headImgRes != null && CommonUtil.isNull(headImgRes.getFullUrl()))) {
                user_icon_default.setVisibility(View.VISIBLE);
                presenter.getHeadImg();
                isLoadHeadImage = true;
            }
        }
    }

    public void showRedMark() {
        if (FinalConfigParams.TRUE.equals(
                PreferencesUtls.getInstance(getActivity()).getString(FinalConfigParams.BROADCAST_UNREAD))) {
            unread_tv.setVisibility(View.VISIBLE);
        } else {
            unread_tv.setVisibility(View.GONE);
        }
    }

    /**
     * 切换环境后重置用户手册url
     */
    private void resetOpManulLink() {
        if (opManualViewData != null) {
            Bundle opManualBundle = new Bundle();
//            opManualBundle.putString("linkUrl", USER_GUIDE_LINK);
//            opManualBundle.putString("topTitle", getString(R.string.user_operation_manual));
//            opManualBundle.putBoolean("canGoBack", true);
            WebDataEntity entity = new WebDataEntity();
            entity.setLinkUrl(USER_GUIDE_LINK);
//            entity.setLinkUrl("http://113.52.176.25:53411/manual/");
//            entity.setLinkUrl("http://emip-jms-con1.idt1.shanghaionstar.com:53421/manual/");

            entity.setTopTitle(getString(R.string.user_operation_manual));
            entity.setCanGoBack(true);
            opManualBundle.putParcelable(IWebType.KEY_WEB_DATA, entity);
            opManualViewData.setBundle(opManualBundle);
        }
    }

    ItemViewData opManualViewData;


    public boolean isCanShowVehicleOpHis() {
        boolean isLogin = ApplicationUtil.getInstance().isLogin();
        String loginRole = ApplicationUtil.getInstance().getLoginRole();
        boolean isProxyOrDriver = !TextUtils.isEmpty(loginRole) && (loginRole.equalsIgnoreCase(Constants.DRIVER) || loginRole.equalsIgnoreCase(Constants.PROXY));
        return !(isLogin && isProxyOrDriver);
    }

    public void showHis() {
        View childView = datas_layout.getChildAt(1);
        if (childView != null)
            childView.setVisibility(isCanShowVehicleOpHis() ? View.VISIBLE : View.GONE);
    }

    private void showDatas() {
        datas_layout.removeAllViews();

        List<ItemViewData> datas = new ArrayList<ItemViewData>();
        ItemViewData viewData = null;

//        if (ApplicationUtil.getInstance().isLogin() && ApplicationUtil.getInstance().getLoginRole().equalsIgnoreCase(JoinMeConstants.VISITOR)) {
//            //visitor 才有升级为车主的Button
//            viewData = new ItemViewData();
//            viewData.setText(getString(R.string.upgradetoowner));
//            datas.add(viewData);
//        }

        viewData = new ItemViewData();
        viewData.setText(getString(R.string.vehicle_info));
        viewData.setClassName(MoreActivity.class.getName());
        Bundle vehicBundle = new Bundle();
        vehicBundle.putString(FinalConstants.JUMP_FLAG, VehicleInfoFragment.class.getName());
        viewData.setFunctionValue(FunctionNameFindId.My_Vehicle.getStringValue());
        viewData.setBundle(vehicBundle);
        datas.add(viewData);


        viewData = new ItemViewData();
        viewData.setClassName(MoreActivity.class.getName());
        Bundle remoteBundle = new Bundle();
        remoteBundle.putString(FinalConstants.JUMP_FLAG, RemoteControlHistoryFragment.class.getName());
        viewData.setBundle(remoteBundle);
        viewData.setText(getString(R.string.remote_control_history_top_title));
        viewData.setFunctionValue(FunctionNameFindId.My_Recenthistory.getStringValue());
        datas.add(viewData);


        /**
         * 7.0不上
         */
        opManualViewData = new

                ItemViewData();

        opManualViewData.setText(

                getString(R.string.user_operation_manual)

        );
        opManualViewData.setClassName(CommonWebViewActivity.class.

                getName()

        );
        opManualViewData.setFunctionValue(FunctionNameFindId.My_Usermanual.getStringValue());
        Bundle opManualBundle = new Bundle();
        WebDataEntity entity = new WebDataEntity();
//        entity.setLinkUrl("http://113.52.176.25:53411/manual/");
        entity.setLinkUrl(USER_GUIDE_LINK);
        entity.setTopTitle(

                getString(R.string.user_operation_manual)

        );
        entity.setCanGoBack(true);
        opManualBundle.putParcelable(IWebType.KEY_WEB_DATA, entity);
//        opManualBundle.putString("linkUrl", USER_GUIDE_LINK);
//        opManualBundle.putString("topTitle", getString(R.string.user_operation_manual));
//        opManualBundle.putBoolean("canGoBack", true);
        opManualViewData.setBundle(opManualBundle);
        datas.add(opManualViewData);

        viewData = new

                ItemViewData();

        viewData.setClassName(MoreActivity.class.

                getName()

        );
        Bundle helpBundle = new Bundle();
        viewData.setFunctionValue(FunctionNameFindId.My_help.getStringValue());
        helpBundle.putString(FinalConstants.JUMP_FLAG, HelpListFragment.class.

                getName()

        );
        viewData.setBundle(helpBundle);
        viewData.setText(

                getString(R.string.make_help)

        );
        datas.add(viewData);

        viewData = new

                ItemViewData();

        viewData.setText(

                getString(R.string.feedback)

        );
        viewData.setClassName(MoreActivity.class.

                getName()

        );
        Bundle feedBackBundle = new Bundle();
        feedBackBundle.putString(FinalConstants.JUMP_FLAG, FeedBackFragment.class.

                getName()

        );
        viewData.setFunctionValue(FunctionNameFindId.My_Feedback.getStringValue());
        viewData.setBundle(feedBackBundle);

        datas.add(viewData);

        viewData = new

                ItemViewData();

        viewData.setText(

                getString(R.string.option_about)

        );
        viewData.setClassName(MoreActivity.class.

                getName()

        );
        Bundle aboutBundle = new Bundle();
        aboutBundle.putString(FinalConstants.JUMP_FLAG, AboutFragment.class.

                getName()

        );
        viewData.setBundle(aboutBundle);
        viewData.setFunctionValue(FunctionNameFindId.My_About.getStringValue());
        datas.add(viewData);

        CustomLayoutsGroup group = new CustomLayoutsGroup(getActivity(), datas);
        group.customLineLayoutGroup(datas_layout);

        group.setOnViewItemClickListener(new CustomLayoutsGroup.OnViewItemClickListener()

                                         {
                                             @Override
                                             public boolean onViewItemClick(ItemViewData item) {
                                                 String functionValue = item.getFunctionValue();
                                                 if (!TextUtils.isEmpty(functionValue) && !functionValue.equalsIgnoreCase("F-1")) {
                                                     BusinessUtil.sendReportByClickType(getActivity(), functionValue);
                                                 }
                                                 if (ApplicationUtil.getInstance().isLogin() && ApplicationUtil.getInstance().getLoginRole().equalsIgnoreCase(JoinMeConstants.VISITOR)) {
                                                     if (item.getText().equalsIgnoreCase(getString(R.string.vehicle_info)) ||
                                                             item.getText().equalsIgnoreCase(getString(R.string.remote_control_history_top_title))) {
                                                         return !isVisitor();
                                                     }
                                                 }
                                                 if (!ApplicationUtil.getInstance().isLogin()) {
                                                     if (item.getText().equalsIgnoreCase(getString(R.string.remote_control_history_top_title)) || item.getText().equalsIgnoreCase(getString(R.string.vehicle_info))) {
                                                         new LoginUtil().loginAndActionCallBack(getActivity(), RxConstants.MORE_PAGE, MoreFragment.this, item.getBundle());
                                                         return false;
                                                     }
                                                 }

               /* if (!ApplicationUtil.getInstance().isLogin()) {
                    if (item.getText().equalsIgnoreCase(getString(R.string.make_help))) {
                        new LoginUtil().loginAndActionCallBack(getActivity(), RxConstants.MORE_PAGE, MoreFragment.this, item.getBundle());
                        return false;
                    }
                }*/
                                                 return true;
                                             }
                                         }

        );
    }

    private boolean isVisitor() {
        if (ApplicationUtil.getInstance().isLogin() && ApplicationUtil.getInstance().getLoginRole().equalsIgnoreCase(JoinMeConstants.VISITOR)) {
            AlertDialogUtil.showAlertDialog(onActivity(), R.string.dialog_warning, R.string.SB021_MSG013,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            progress_dialog = new ProgressDialog(onActivity());
                            progress_dialog.setMessage(getString(R.string.sendingRequest_wait));
                            JoinMeUtils.checkVisitor(MoreFragment.this);
                            BusinessUtil.sendReportByClickType(getActivity(), FunctionNameFindId.My_updatetosubscriber.getStringValue());
                        }
                    }, true, R.string.upgrade_to_owner);
            return true;
        }
        return false;
    }

    @OnClick({R.id.more_setting, R.id.more_broadcast, R.id.package_layout, R.id.data_4g_layout, R.id.ppc_layout, R.id.user_icon, R.id.user_login, R.id.user_icon_default})
    public void onClick(View view) {
        Bundle bundle = new Bundle();
        switch (view.getId()) {
            case R.id.more_setting:
                BusinessUtil.sendReportByClickType(getActivity(), FunctionNameFindId.My_settings.getStringValue());//我的_点击设置
                Intent intent = new Intent(getActivity(), MoreActivity.class);
                intent.putExtra(FinalConstants.JUMP_FLAG, SettingFragment.class.getName());
                startActivity(intent);
                break;
            case R.id.more_broadcast:
                BusinessUtil.sendReportByClickType(getActivity(), FunctionNameFindId.My_message.getStringValue());//我的_点击消息中心
                presenter.broadCastClick();
                intent = new Intent(getActivity(), MoreActivity.class);
                intent.putExtra(FinalConstants.JUMP_FLAG, BroadcastFragment.class.getName());
                startActivity(intent);
//                Snackbar snackbar=Snackbar.make(user_login,"网络已断开，请重试",Snackbar.LENGTH_LONG).setAction("retry",new View.OnClickListener(){
//                    @Override
//                    public void onClick(View view) {
//
//                    }
//                });
//                设置位置，默认位置是在底部
//                ViewGroup.LayoutParams vl = snackbar.getView().getLayoutParams();
//                LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(vl.width,vl.height);
//                ll.gravity = Gravity.TOP;
//                snackbar.getView().setLayoutParams(ll);
//                snackbar.show();
                break;
            case R.id.data_4g_layout:
                BusinessUtil.sendReportByClickType(getActivity(), FunctionNameFindId.My_4Gpackage.getStringValue());
                bundle.putString(FinalConstants.JUMP_FLAG, CurrentDataPackageActivity.class.getName());
                bundle.putBoolean(FinalConstants.CHECK_VISITOR, true);
                new LoginUtil().loginAndActionCallBack(getActivity(), RxConstants.MORE_PAGE, this, bundle);
                break;
            case R.id.package_layout:
                BusinessUtil.sendReportByClickType(getActivity(), FunctionNameFindId.My_OnstarPackage.getStringValue());
                bundle.putString(FinalConstants.JUMP_FLAG, OnStarPackageListActivity.class.getName());
                bundle.putBoolean(FinalConstants.CHECK_VISITOR, true);
                new LoginUtil().loginAndActionCallBack(getActivity(), RxConstants.MORE_PAGE, this, bundle);
                break;
            case R.id.ppc_layout:
                BusinessUtil.sendReportByClickType(getActivity(), FunctionNameFindId.My_Prepaidcardactive.getStringValue());
//                if (!ApplicationUtil.getInstance().isLogin()) {
                bundle.putString(FinalConstants.JUMP_FLAG, PrePayActivity.class.getName());
                bundle.putBoolean(FinalConstants.CHECK_VISITOR, true);
                new LoginUtil().loginAndActionCallBack(getActivity(), RxConstants.MORE_PAGE, this, bundle);
//                } else {
//                    intent = new Intent(getActivity(), PrePayActivity.class);
//                    startActivity(intent);
//                }

               /* bundle.putString(FinalConstants.JUMP_FLAG, PrePayActivity.class.getName());
                bundle.putBoolean(FinalConstants.CHECK_VISITOR, true);
                new LoginUtil().loginAndActionCallBack(getActivity(), RxConstants.MORE_PAGE, this, bundle);*/
                break;
            case R.id.user_icon:
            case R.id.user_icon_default:
            case R.id.user_login:
                if (ApplicationUtil.getInstance().isLogin()) {
                    BusinessUtil.sendReportByClickType(getActivity(), FunctionNameFindId.My_Personalinformation.getStringValue());//我的_点击个人中心
                    intent = new Intent(getActivity(), MoreActivity.class);
                    intent.putExtra(FinalConstants.JUMP_FLAG, AccountInfoFragment.class.getName());
                    startActivity(intent);
//                    try {
////                        bundle.putString(FinalConstants.JUMP_FLAG, AccountInfoFragment.class.getName());
////                        String className = bundle.getString(FinalConstants.JUMP_FLAG);
////                        Class<?> clazz = Class.forName(className);
////                        BusinessUtil.jumpActivity(bundle, this, clazz);
//                    }catch (Exception e){
//                        e.printStackTrace();
//                    }
                } else {
                    BusinessUtil.sendReportByClickType(getActivity(), FunctionNameFindId.My_Loginregister.getStringValue());//我的_登录注册
                    new LoginUtil().loginAndActionCallBack(getActivity(), RxConstants.MORE_PAGE, this, bundle);
                }
//                bundle.putString(FinalConstants.JUMP_FLAG, AccountInfoFragment.class.getName());
//                bundle.putString(FinalConstants.JUMP_FLAG, AccountInfoFragment.class.getName());
//                new LoginUtil().loginAndActionCallBack(getActivity(), RxConstants.MORE_PAGE, this, bundle);
                break;
            default:
                break;
        }
    }

    private static final String PULL_REFRESH_GUIDE = "pullRefreshGuide";

    private void showPullRefreshGuide() {
        boolean cacheShowState = PreferencesUtls.getInstance(baseActivity).getBoolean(PULL_REFRESH_GUIDE, true);
        img_pullRefreshGuide.setVisibility(cacheShowState ? View.VISIBLE : View.GONE);
    }

    private void hidePullRefreshGuide() {
        if (ApplicationUtil.getInstance().isLogin()) {
            img_pullRefreshGuide.setVisibility(View.GONE);
            PreferencesUtls.getInstance(baseActivity).putBoolean(PULL_REFRESH_GUIDE, false);
        }
    }

    @Override
    public void onLogin(Bundle bundle, String resultCode) {
        //登录成功
        asyncData();
        showDatas();
        initButton();


/*
        if (bundle != null) {
            if (isVisitor()) {
                return;
            }
            try {
                BaseFragmentActivity activity = (BaseFragmentActivity) onActivity();
                Class<?> clazz = Class.forName(bundle.getString(FinalConstants.JUMP_FLAG,MoreActivity.class.getName()));
                if (clazz.newInstance() instanceof Fragment) {
                    Fragment fragment = (Fragment) clazz.newInstance();
                    if (!CommonUtil.isNull(bundle)) {
                        fragment.setArguments(bundle);
                    }
                    activity.changeFragment(fragment, clazz, false);
                } else {
                    Intent intent = new Intent(activity, clazz);
                    if (!CommonUtil.isNull(bundle)) {
                        intent.putExtras(bundle);
                    }
                    activity.startActivity(intent);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

*/

        if (bundle != null) {
            if (bundle.getBoolean(FinalConstants.CHECK_VISITOR, false)) {
                if (isVisitor()) {
                    return;
                }
            }

            if (ApplicationUtil.getInstance().isLogin() && ApplicationUtil.getInstance().getLoginRole().equalsIgnoreCase(JoinMeConstants.VISITOR)) {
                return;
            }
            try {
                String className = bundle.getString(FinalConstants.JUMP_FLAG);

                Class<?> clazz = Class.forName(className);
                BusinessUtil.jumpActivity(bundle, this, clazz);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }


    @Override
    public void setLoading(boolean isLoading) {
        if (progress_dialog != null) {
            if (isLoading) {
                if (!progress_dialog.isShowing()) progress_dialog.show();
            } else {
                if (progress_dialog.isShowing())
                    progress_dialog.dismiss();
            }
        }
    }

    @Override
    public void onResponseError(OnStarException e) {

        //加载头像失败提示
//        AlertDialogUtil.showDialogByOnstarException(getActivity(),e);
        if (e != null) {
            new ToastView(baseActivity).showToast(e.getMessage());
        }
    }

    @Override
    public void onReponseSuccess(HeadImgRes object) {
        if (object != null && !CommonUtil.isNull(object.getFullUrl())) {
            showHeadImage(object);
            //   ShareUtils.put("imageUrl", object.getFullUrl(), getActivity());
            application.setHeadImgRes(object);
        }
    }

    @Override
    public Activity onActivity() {
        return getActivity();
    }

    @Override
    public void getHeadError() {
        user_icon_default.setVisibility(View.VISIBLE);
    }
}
